package com.hhl.flower.controller;

import com.hhl.flower.common.result.Result;
import com.hhl.flower.context.BaseContext;
import com.hhl.flower.pojo.entity.Flower;
import com.hhl.flower.service.CollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/collection")
@Api(tags = "用户收藏相关接口")
@Slf4j
public class CollectionController {
	@Autowired
	private CollectionService collectionService;

	@GetMapping("/list")
	@ApiOperation("获取用户收藏鲜花列表")
	public Result<List<Flower>> list() {
		Integer userId = BaseContext.getCurrentId();

		List<Flower> flowerList = collectionService.listCollectionFlower(userId);

		return Result.success(flowerList);
	}

	@PostMapping("/likeOrCancel")
	@ApiOperation("用户收藏花/取消收藏")
	public Result<String> likeOrCancel(@RequestParam("status") Boolean status, @RequestParam("fid") Integer fid) {
		Integer userId = BaseContext.getCurrentId();

		collectionService.likeOrCancel(status, fid, userId);

		return Result.success();
	}

	@GetMapping("/attitude")
	@ApiOperation("查询用户是否收藏花")
	public Result<Boolean> isCollection(@RequestParam Integer fid) {
		Integer userId = BaseContext.getCurrentId();

		Boolean collection = collectionService.isCollection(fid, userId);

		return Result.success(collection);
	}
}
